package com.shopping.adminServlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shopping.service.AdminService;
import com.shopping.service.impl.AdminServiceImpl;

/**
 * @author 216
 *	管理员登录
 */
@WebServlet("/loginAdmin.do")
public class LoginAdminServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req,resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String adminName = req.getParameter("adminName");
		String password = req.getParameter("password");
		AdminService as = new AdminServiceImpl();
		Map<String,Object> map = as.loginAdmin(adminName, password);
		if(map.get("adminLogin") !=null) {
			req.getSession().setAttribute("adminLogin", map.get("adminLogin"));
			req.getRequestDispatcher("admin.jsp").forward(req, resp);
		}else {
			req.setAttribute("msg", map.get("erroCode"));
			req.getRequestDispatcher("adminLogin.jsp").forward(req, resp);
		}
	}

	
	
}
